import java.util.Random;

/**
 * Content: Java反射技术
 * --------------------------------------------------
 * Java之反射: https://juejin.cn/post/6905686843091025933
 */

public class java_1400_Reflect {
    public static void main(String[] args) {

        // Java反射技术
        System.out.println("--------------------Java反射技术--------------------");

        for (int i = 0; i < 100; i++) {
            int num = new Random().nextInt(3);//0,1,2
            String classPath = "";
            switch (num) {
                case 0:
                    classPath = "java.util.Date";
                    break;
                case 1:
                    classPath = "java.lang.Object";
                    break;
                case 2:
                    classPath = "com.atguigu.java.Person";
                    break;
            }

            try {

                Object obj = getInstance(classPath);
                System.out.println(obj);

            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }

    static Object getInstance(String classPath) throws Exception {
        Class clazz =  Class.forName(classPath);
        return clazz.newInstance();
    }

}
